home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / Example Scripts / MWLocal.vu < prev    next >
Encoding:
Text File  |  1998-06-04  |  6.9 KB  |  220 lines  |  [TEXT/MPS ]

  1. #
  2. #    File:        MWLocal.vu
  3. #
  4. #    Contains:    Sample demo working with MacWrite II 1.1 on a variety of
  5. #                localized systems. Script assumes you have MacWrite II application
  6. #                active.
  7. #
  8. #    Written by:    David Gaxiola
  9. #
  10. #    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  11. #
  12. #    Change History (most recent first):
  13. #
  14. #                 3/4/96            JC        Changed some checkbox ordinalities.
  15. #                 7/20/92        DGG        Edited Resources
  16. #                 7/16/92        DGG        Created.
  17. #
  18. #    To Do:
  19. #
  20.  
  21. Libraries "UtilityTasks.vulib","StandardDialogs.vulib","DataUtils.vulib",
  22.             "QuickTasks.vulib";
  23. (************************************************************************************
  24. * Task GetLocalVersion()
  25. *    Get the specific country for a version of Mac O/S based on the value
  26. *    for the system descriptor.
  27. ************************************************************************************)
  28. task GetLocalVersion()
  29. begin
  30.     match [system v:?sysVersion];
  31.  
  32.     if (sysVersion ~= /≈E1-≈/)
  33.         return "Spanish";
  34.     else 
  35.         return "USA";
  36. end;
  37.  
  38. (************************************************************************************
  39. * Task DoSaveAsLocal(saveTitle)
  40. *    Handle the standard file dialog in multiple languages.  The global variables
  41. *    specify the localized versions of the names to common buttons that may
  42. *    be encountered in the Save As… dialogs.
  43. ************************************************************************************)
  44. task DoSaveAsLocal(saveTitle := 'Untitled') 
  45. begin
  46.     wType := dialog;                            #see if dialog appeared
  47.     global gReplaceButtonName;                    #buttons to check for
  48.     global gYesButtonName;
  49.     global gSaveButtonName;
  50.     global gSaveAsMenuItemName;
  51.  
  52.     println "# Handling 'SaveAs' dialog.";
  53.     select [menuItem t:/{gSaveAsMenuItemName}≈/];        #menu selection
  54.     type k:{ saveTitle };                                #literal key strokes
  55.     select [button t:gSaveButtonName];                    #button press
  56.     # if the file exists, the "Do you want to replace" dialog will come up
  57.     # These if statements recognize that dialog and deal with it
  58.     if match[window s:wType]
  59.     begin
  60.         if match[button t:gReplaceButtonName e:false]
  61.             select[button t:gReplaceButtonName]; 
  62.         else if match[button t:gYesButtonName e:false]
  63.             select[button t:gYesButtonName];
  64.     end;
  65. end; # task DoSaveAs
  66.  
  67. (************************************************************************************
  68. * Task GenerateSomeText()
  69. *    This task will output a message to the currently active window.  One may
  70. *    note that this is a modified form of the GenerateSomeText found in the
  71. *    AppleLink.vu script.
  72. ************************************************************************************)
  73. task GenerateSomeText()
  74. begin
  75.     global gTheCatcher;
  76.     global gTheListOfStrings;
  77.     global gFontMenuName;
  78.     global gFormatMenuName;
  79.     global gSizeMenuName;
  80.     global gCharacterMenuItemName;
  81.     
  82.     numberOfFonts := card collect [menuItem m:gFontMenuName];
  83.     
  84.     println "# Now setting character attributes.";
  85.     
  86.     select [menuItem t:gCharacterMenuItemName m:/{gFormatMenuName}≈/];
  87.     DoCheckBox(26);
  88.     DoCheckBox(35);
  89.     select [button t:/≈OK≈/ w:1];
  90.     
  91.     select [menuItem t:"Helvetica" m:gFontMenuName];
  92.     select [menuItem t:"36" m:gSizeMenuName];
  93.     
  94.     type k:{gTheCatcher, returnKey};
  95.     println "# Now cutting to clipboard.";
  96.     UseKeyboardEquivalent("a");
  97.     UseKeyboardEquivalent("x");
  98.     
  99.     for each singleString in gTheListOfStrings
  100.     begin
  101.         println "# Now typing: {singleString}";
  102.         type k:{singleString, returnKey};
  103.         UseKeyboardEquivalent("t");
  104.     end;
  105.     
  106.     for counter := 1 to 5
  107.     begin
  108.         println "# Now pasting from clipboard.";
  109.         UseKeyboardEquivalent("v");
  110.     end;
  111. end;
  112.  
  113. (************************************************************************************
  114. * Task EditTheText()
  115. *    This task will perform a search and replace on the the text in the 
  116. *    currently active window.  Note that errors in typing may cause this task
  117. *    to fail.
  118. ************************************************************************************)
  119. task EditTheText(stringToSearch := "", stringToReplace := "")
  120. begin
  121.  
  122.     global gEditMenuName;
  123.     global gFindDialogName;
  124.     global gFindButtonName;
  125.     global gChangeButtonName;
  126.     
  127.     println "# Now performing Find/Change operations.";
  128.     
  129.     match [window o:1 r:?docPosition];
  130.     select [menuItem t:/{gFindDialogName}≈/ m:gEditMenuName];
  131.     drag [window o:1 t:gFindDialogName] a:{docPosition[1],docPosition[2]};
  132.     type k:{stringToSearch, tabKey, stringToReplace};
  133.     select [button t:gFindButtonName w:gFindDialogName];
  134.     match [window o:1 s:?topWinStyle];
  135.     if (topWinStyle = dialog)
  136.     begin
  137.         select [button t:/≈OK≈/ w:[window o:1]];
  138.         println "### Find command failed!";
  139.     end;
  140.     else
  141.         select [button t:gChangeButtonName w:gFindDialogName];
  142.     close [window t:gFindDialogName];
  143. end;
  144.  
  145. # Main Script
  146. script MWLocalMain()
  147. begin
  148.     localVersion := getLocalVersion();
  149.     
  150.     usaMenuID := 128;
  151.     usaDialogID := 130;
  152.     usaMenuItemID := 132;
  153.     usaMessageID := 134;
  154.     espMenuID := 129;
  155.     espDialogID := 131;
  156.     espMenuItemID := 133;
  157.     espMessageID := 135;
  158.     
  159.     if (localVersion = "USA")
  160.     begin
  161.         menuID := usaMenuID;
  162.         dialogID := usaDialogID;
  163.         menuItemID := usaMenuItemID;
  164.         messageID := usaMessageID;
  165.     end;
  166.     else if (localVersion = "Spanish")
  167.     begin
  168.         menuID := espMenuID;
  169.         dialogID := espDialogID;
  170.         menuItemID := espMenuItemID;
  171.         messageID := espMessageID;
  172.     end;
  173.  
  174.     global gFileMenuName := getIndString(menuID, 1); 
  175.     global gEditMenuName := getIndString(menuID, 2);
  176.     global gFontMenuName := getIndString(menuID, 3);
  177.     global gSizeMenuName := getIndString(menuID, 4);
  178.     global gStyleMenuName := getIndString(menuID, 5);
  179.     global gFormatMenuName := getIndString(menuID, 6);
  180.     global gFindDialogName := getIndString(dialogID, 1);
  181.     global gFindButtonName := getIndString(dialogID, 2);
  182.     global gChangeButtonName := getIndString(dialogID, 3);
  183.     global gSaveButtonName := getIndString(dialogID, 4);
  184.     global gYesButtonName := getIndString(dialogID, 5);
  185.     global gReplaceButtonName := getIndString(dialogID, 6);    
  186.     global gNewMenuItemName := getIndString(menuItemID, 1);
  187.     global gOpenMenuItemName := getIndString(menuItemID, 2);
  188.     global gSaveAsMenuItemName := getIndString(menuItemID, 3);
  189.     global gCharacterMenuItemName := getIndString(menuItemID, 4);
  190.     global gTheCatcher := getIndString(messageID,1);
  191.     global gTheListOfStrings := {" ", " ", " "};
  192.     gTheListOfStrings := replace(getIndString(messageID,2),1,gTheListOfStrings);
  193.     gTheListOfStrings := replace(getIndString(messageID,3),2,gTheListOfStrings);
  194.     gTheListOfStrings := replace(getIndString(messageID,4),3,gTheListOfStrings);
  195.  
  196.     theSearchString := gTheListOfStrings[2];
  197.     theReplaceString := "this application, which we think is the best in Automated Testing.";
  198.     savedName := "VU MacWriteII Demo";
  199.  
  200.     println "# Beginning MacWrite II Tests";
  201.     
  202.     # Create the new document.
  203.     select [menuItem t:gNewMenuItemName m:gFileMenuName];
  204.     GenerateSomeText();
  205.     
  206.     # Save and close it.
  207.     DoSaveAsLocal(savedName);
  208.     close [window t:savedName];
  209.     
  210.     # Reopen the document and edit it.
  211.     select [menuItem t:/{gOpenMenuItemName}≈/ m:gFileMenuName];
  212.     SelectFromStandardFile({ConcatStrings({savedName[1],savedName[2],savedName[3]})}, 
  213.                             0);
  214.     EditTheText(theSearchString, theReplaceString);
  215.  
  216.     # Save it again.
  217.     DoSaveAsLocal(savedName);
  218.     
  219.     close [window t:savedName o:1];
  220. end;